package sealte.hvpms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sealte.hvpms.dao.impl.RulesDAOImpl;
import sealte.hvpms.pojo.Admin;

public class AdminChangeRuleIsUsed extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		Admin admin = (Admin)request.getSession().getAttribute("admin");
		PrintWriter out = response.getWriter();
		if(admin!=null){
			String id_str = (String)request.getParameter("id");
			String isUsed = (String)request.getParameter("isused");
			int id = Integer.parseInt(id_str);
			isUsed = (isUsed.equals("N"))?"Y":"N";
			RulesDAOImpl rb = new RulesDAOImpl();
			boolean flag = rb.changeIsUsed(isUsed, id);
			String message = "";
			if(flag){
				message = "修改-是否可用-成功";
			}else{
				message = "修改-是否可用-失败！";
			}
			request.setAttribute("message_ciu", message);
			request.getRequestDispatcher("hvpms_admin/rules_management.jsp").forward(request, response);
		}else{
			out.println("谢绝跨路径访问！");
		}
	}

}
